package com.wjsima.renyisima.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class HomeWork2 {
    public static <HashMap> void doJob(HashMap t, Consumer<HashMap> consumer) {
        consumer.accept(t);
    }
    public static <HashMap> void doJob(HashMap t, Consumer<HashMap> consumer1, Consumer<HashMap> consumer2) {
        consumer1.andThen(consumer2).accept(t);
    }

    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();

        //key:姓名 value:成绩
        map.put("岑小村",59);
        map.put("谷天洛",82);
        map.put("渣渣辉",98);
        map.put("蓝小月",65);
        map.put("皮几万",70);
//          a)打印谷天洛的分数
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        Stream<Map.Entry<String, Integer>> stream = entries.stream();
        stream.forEach(stringIntegerEntry -> {
            if (stringIntegerEntry.getKey().equals("谷天洛")){
                System.out.println(stringIntegerEntry.getKey() + "  " + stringIntegerEntry.getValue());
            }
        });
        System.out.println("---------------");
//          b)打印最高分
        Stream<Map.Entry<String, Integer>> stream2 = entries.stream();

        stream2.forEach((s) -> {

        });



//          c)分别以60分和70分为及格线，打印及格的人的名字(组合型消费)
        Stream<Map.Entry<String, Integer>> stream3 = entries.stream();
        stream3.forEach(new Consumer<Map.Entry<String, Integer>>() {
            @Override
            public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
                if (stringIntegerEntry.getValue()>= 60){
                    String key = stringIntegerEntry.getKey();
                    System.out.println(key);
                }
            }
        });
        System.out.println("------------------");
        Stream<Map.Entry<String, Integer>> stream4 = entries.stream();
        stream4.forEach(new Consumer<Map.Entry<String, Integer>>() {
            @Override
            public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
                if (stringIntegerEntry.getValue()>= 70){
                    String key = stringIntegerEntry.getKey();
                    System.out.println(key);
                }
            }
        });
    }
}
